"""负责外星飞船的控制的类"""
import pygame as ga
from pygame.sprite import Sprite

class Alien(Sprite):
    """负责单个外星人的类"""
    def __init__(self,ai_game):
        """初始化外星人并且设置好初识位置"""
        super().__init__()
        self.screen = ai_game.screen
        self.set = ai_game.set
        # 加载外星人图片并且设置其rect信息
        self.image = ga.image.load('Picture/飞船.bmp')
        self.new_width = 50
        self.new_height = 50
        self.image = ga.transform.scale(self.image, (self.new_width, self.new_height))
        self.rect = self.image.get_rect()
        #设置初始化位置,每个外星人的位置都是屏幕左上角
        self.rect.x = self.rect.width
        self.rect.y = self.rect.height
        #存储外星人的精确位置
        self.x = float(self.rect.x)

    def check_edges(self):
        """负责判断外星人是否移动到边缘的函数"""
        screen_rect = self.screen.get_rect()
        return (self.rect.right >= screen_rect.right) or (self.rect.left <= 0)
    
    def update(self):
        """负责外星人进行移动的函数"""
        self.x += self.set.alien_speed*self.set.fleet_direction
        self.rect.x = self.x 

